package com.earl.gsm.web.match;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.earl.gsm.commons.vo.ResultMessage;
import com.earl.gsm.domain.gsm.match.Player;
import com.earl.gsm.domain.sercurity.user.User;
import com.earl.gsm.service.PlayerInfoService;
import com.earl.gsm.web.BaseController;
import com.wordnik.swagger.annotations.ApiOperation;

@Controller
@RequestMapping(value = "/match/team/player")
//@Api(value="Person Rest Service") //修改生成的son路径
public class PlayerInfoController extends BaseController {

    private final Logger log = LoggerFactory.getLogger(PlayerInfoController.class);

    @Autowired
    private PlayerInfoService service;

    private ResultMessage result = null;

    /**
     * GET /users -> get all the users
     */
    @RequestMapping(value = "/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "得到所有队员信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ModelAndView getAll() {
        log.debug("REST request to get all Users");
        return new ModelAndView("match/allPlayer","playerList",service.findAll());
    }

    /**
     * GET /users -> get all the users
     */
    @RequestMapping(value = "/preAdd",produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "得到所有队员信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public String preAdd() {
        log.debug("REST request to get all Users");
        return "player/addPlayer";
    }
    
    @RequestMapping(value="/add")
    @ApiOperation(value = "添加队员信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ResponseEntity<ResultMessage> applyForMatch(Player playerInfo){
                service.save(playerInfo);
        return new ResponseEntity<ResultMessage>(result, HttpStatus.OK);
    }
    
    @RequestMapping(value="/preUpdate/{playerId}")
    @ApiOperation(value = "添加队员信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ModelAndView preUpdate(@PathVariable Long playerId){
                
        return new ModelAndView("player/preUpdate","player",service.findOne(playerId));
    }

    
    @RequestMapping(value="/update")
    @ApiOperation(value = "更新队员信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ResponseEntity<ResultMessage> compeletePlayerInfo(){
        return null;
    }

    @RequestMapping(value="/pointTeam/{teamId}")
    @ApiOperation(value = "得到指定队员信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ModelAndView pointTeamPlayer(@PathVariable Long teamId){
    	
    	Player player = new Player();
    	player.setTeamId(teamId);
        return new ModelAndView("match/allPlayer","playerList",service.searchQuery(player));
    }

}
